package net.akkz.action.imgView;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.akkz.beanFactory.BeanFactory;
import net.akkz.model.ImgView;
import net.akkz.model.Student;
import net.akkz.server.ImgViewServer;

@WebServlet(name="ImgViewFind", urlPatterns="/student/imgViewFind.do")
public class ImgViewFind extends HttpServlet
{
	private ImgViewServer imgViewServer;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
	{
		doPost(request, response);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
	{
		int start = Integer.parseInt(request.getParameter("start"));
		int end = Integer.parseInt(request.getParameter("end"));
		
		String kind = request.getParameter("kind");
		
		ArrayList<ImgView> result;
		
		if(kind.equals("time"))
		{
			result = imgViewServer.findImgView(start, end);
		}
		else
		{
			result = imgViewServer.findImgViewOrderbyGoodNum(start, end);
		}
		
		request.setAttribute("imgViews", result);
		
		request.getRequestDispatcher("/jsp/ImgViews.jsp").forward(request, response);
	}
	
	@Override
	public void init()
	{
		BeanFactory  bf = (BeanFactory) this.getServletContext().getAttribute("beanFactory");
		
		imgViewServer = bf.getBean("imgViewServer");
	}
}
